﻿using Sustainalytics.ClientDW.Synchronization.SyncESGData.AbstractClassesAndInterfaces;
using Sustainalytics.SharedEntities.EsgResearch;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.CompanyKeyESGIssueLogic
{
    public class CompanyKeyESGIssueOrchestrator : IComprehensiveEsgSyncOrchestrator<EsgResearchProfile>
    {
        private readonly CompanyKeyESGIssueMapper companyKeyESGIssueMapper;
        private readonly CompanyKeyESGIssueCommand companyKeyESGIssueCommand;
        private readonly CompanyKeyESGIssueProcessor companyKeyESGIssueProcessor;

        public CompanyKeyESGIssueOrchestrator(CompanyKeyESGIssueMapper companyKeyESGIssueMapper, CompanyKeyESGIssueCommand companyKeyESGIssueCommand, CompanyKeyESGIssueProcessor companyKeyESGIssueProcessor)
        {
            this.companyKeyESGIssueMapper = companyKeyESGIssueMapper;
            this.companyKeyESGIssueCommand = companyKeyESGIssueCommand;
            this.companyKeyESGIssueProcessor = companyKeyESGIssueProcessor;
        }

        async Task IComprehensiveEsgSyncOrchestrator<EsgResearchProfile>.OrchestrateAsync(IList<EsgResearchProfile> comprehensiveEsgResearchProfiles, IList<Guid> invalidatedCompaniesIds)
        {
            var companyKeyEsgIssues = companyKeyESGIssueMapper.MapManyToMany(comprehensiveEsgResearchProfiles);

            companyKeyESGIssueProcessor.AddDescriptionToCompanyKeyEsgIssues(companyKeyEsgIssues);
            companyKeyESGIssueProcessor.AddEventIndicatorDetails(companyKeyEsgIssues);

            await companyKeyESGIssueCommand.ExecuteAsync(companyKeyEsgIssues, invalidatedCompaniesIds);
        }
    }
}
